<%--
  Created by IntelliJ IDEA.
  User: Sruo
  Date: 2024/12/17
  Time: 15:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.iqoo.store.model.Product" %>
<%@ page import="com.iqoo.store.dao.ProductDao" %>
<%@ page import="com.iqoo.store.model.User" %>
<%
  int productId = Integer.parseInt(request.getParameter("id"));
  ProductDao productDao = new ProductDao();
  Product product = productDao.findById(productId);
  User user = (User) session.getAttribute("user");
%>
<!DOCTYPE html>
<html>
<head>
  <title><%= product.getName() %> 详情</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="styles.css"> <!-- 引入CSS样式 -->
  <style>
    /* 汉堡菜单样式 */
    .hamburger {
      display: none;
      cursor: pointer;
      padding: 10px;
    }

    .hamburger-line {
      width: 25px;
      height: 3px;
      background-color: #fff;
      margin: 5px 0;
      transition: all 0.3s ease;
      right: 0;
    }

    /* 响应式样式 */
    @media (max-width: 768px) {
      .hamburger {
        display: block;
        position: absolute;   /* 绝对定位 */
        right: 15px;          /* 距离右侧 15px */
      }

      .navbar-right {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        width: 100%;
        background-color: #333;
        flex-direction: column;
        padding: 10px 0;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
      }

      .navbar-right.active {
        display: flex;
      }

      .navbar-right a, .navbar-right span {
        padding: 10px 20px;
        border-bottom: 1px solid #333;
      }
    }
  </style>
</head>
<body>
<div class="navbar">
  <div class="navbar-left">
    <a href="index.jsp" class="logo">iQOO的小店</a>
  </div>
  <div class="navbar-right" id="navbarRight">
    <% if (user == null) { %>
    <a href="index.jsp">主页</a>
    <a href="register.jsp">注册</a>
    <a href="login.jsp">登录</a>
    <% } else { %>
    <span>欢迎, <%= user.getUsername() %>!</span>
    <% if(user.getRole() == 1) { %>
    <% } %>
    <a href="index.jsp">主页</a>
    <a href="goods.jsp">商品列表</a>
    <a href="cart.jsp">购物车</a>
    <% } %>
  </div>
  <div class="hamburger" onclick="toggleMenu()">
    <div class="hamburger-line"></div>
    <div class="hamburger-line"></div>
    <div class="hamburger-line"></div>
  </div>
</div>
<div class="container">
  <h1><%= product.getName() %></h1>
  <p><%= product.getDescription() %></p>
  <p>价格: ¥<%= product.getPrice() %></p>
  <p>库存: <%= product.getStock() %></p>
  <img src="<%= product.getImageUrl() != null ? product.getImageUrl() : "default.jpg" %>" alt="<%= product.getName() %>" width="300">
  <form action="addToCart" method="post">
    <input type="hidden" name="product_id" value="<%= product.getId() %>">
    <button type="submit">加入购物车</button>
  </form>
</div>
<script>
  function toggleMenu() {
    const navbarRight = document.getElementById('navbarRight');
    navbarRight.classList.toggle('active');
  }
</script>
</body>
</html>